package com.onec.service.thread.sync;

public class ParkingStatus {


    private final Object contrlCars, contrlMotoCls;

    private long numberCar;
    private long numberMotorCycles;
    private ParkingCash cash;


    public ParkingStatus(ParkingCash cash) {
        this.numberCar = 0;
        this.numberMotorCycles = 0;
        this.cash = cash;
        contrlMotoCls = new Object();
        contrlCars = new Object();
    }

    public void carComeIn() {
        synchronized (contrlCars) {
            numberCar++;
        }
    }

    public void carGoOut() {
        synchronized (contrlCars) {
            numberCar--;
        }
        cash.vehiclePay();
    }

    public void motorComeIn() {
        synchronized (contrlMotoCls) {
            numberMotorCycles++;
        }
    }

    public void motorGoOut() {
        synchronized (contrlMotoCls) {
            numberMotorCycles--;
        }
        cash.vehiclePay();
    }


    public long getNumberCar() {
        return numberCar;
    }

    public void setNumberCar(long numberCar) {
        this.numberCar = numberCar;
    }

    public long getNumberMotorCycles() {
        return numberMotorCycles;
    }

    public void setNumberMotorCycles(long numberMotorCycles) {
        this.numberMotorCycles = numberMotorCycles;
    }

    public ParkingCash getCash() {
        return cash;
    }

    public void setCash(ParkingCash cash) {
        this.cash = cash;
    }
}
